package game;

import game.maps.Brick;
import game.sounds.MP3;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class Audio {
	
	Model model;
	
	int lastPlayedX = 0;
	int lastPlayedY = 0;

	public Audio(Model model) {
		this.model = model;
	}
	
	private static MP3 mp3 = new MP3("sounds/jazz.mp3");
	
	public static void startMusic() {
		mp3.play();
	}
	
	public void initialize() {
		
		
		
		
		model.getMyPlayer().addCollisionListener(new CollisionListener() {
			
			@Override
			public void collision(List<Collision> collisions) {		
				
				//model.getInfoBar().setLife1(model.getInfoBar().getLife1()-1);
				
				for (Collision collision : collisions) {
				
				if (Math.abs(model.getMyPlayer().getX()-lastPlayedX)>10 || Math.abs(model.getMyPlayer().getY()-lastPlayedY)>10){
		        	//System.out.println("X:" + x + " Y:" + y);
		        	//System.out.println("A:" + lastPlayedX + " B:" + lastPlayedY);
		        
					/*
		        	InputStream in = null;
					try {
					
						if (collision.getObject() instanceof Player){
							in = new FileInputStream("sounds/uu.wav");
							AudioStream as = new AudioStream(in);   
							AudioPlayer.player.start(as);
							lastPlayedX = model.getMyPlayer().getX();
							lastPlayedY = model.getMyPlayer().getY();
						}
						
			
					} catch (Exception e1) { 
						e1.printStackTrace();
					}
					*/
				}
				
			}
				
			}
		});
	}
	
}
